using System;
using System.Collections.Generic;
using System.Text;

namespace FE
{
    public class GameStateMachine<U, V>
    {
        private GameState<U, V> current;
        public GameStateMachine(GameState<U, V> start) {
            this.current = start;
        }
        public GameState<U, V> Current
        {
            get { return current; }
        }
        public void Input(V input)
        {
            foreach (GameStateTransition<U, V> transition in current.transitions)
                if (input.Equals(transition.Input))
                {
                    current = transition.State;
                }
        }
        public bool HasTransition(V input)
        {
            foreach (GameStateTransition<U, V> transition in current.transitions)
                if (input.Equals(transition.Input))
                {
                    return true;
                }
            return false;
        }
        public class GameState <S, T> {            
            S action;
            public List<GameStateTransition<S, T>> transitions = new List<GameStateTransition<S, T>>();
            public GameState(S action)
            {                
                this.action = action;                
            }
            public void AddTransition (T input, GameState<S,T> state) {
                GameStateTransition<S, T> transition = new GameStateTransition<S, T>();
                transition.Input = input;
                transition.State = state;
                transitions.Add(transition);
            }
            public S Action
            {
                get { return action; }
            }

        }
        public class GameStateTransition<Q, P>
        {
            public P Input;
            public GameState<Q, P> State;
        }
        
    }
}
